﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.ServiceModel;
using System.Web;
using System.Web.Script.Services;
using System.Web.Services;
using DotNetNuke.Entities.Users;
using System.Linq;
using Ventrian.SimpleGallery.Entities;

namespace DNNRest
{
    /// <summary>
    /// Summary description for Service1
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class Connect : WebService
    {
        [WebMethod]
        public List<User> GetUsers(int PortalId)
        {
            var totalRecords = 0;
            var arr = UserController.GetUsers(PortalId, 1, 10, ref totalRecords);
            var users = new List<User>();

            foreach (var u in arr)
            {
                var userInfo = (UserInfo)u;

                var user = new User { UserId = userInfo.UserID, UserName = userInfo.Username };
                users.Add(user);
            }

            return users;
        }

        [WebMethod]
        public void AddPhoto(string name)
        {
            try
            {
                var req = HttpContext.Current.Request;

                var count = req.Files.Count;

                File.WriteAllText(Server.MapPath("/") + name + DateTime.Now.Second + DateTime.Now.Minute + ".txt", count.ToString());
            }
            catch (Exception exc)
            {
                File.WriteAllText(Server.MapPath("/") + name + DateTime.Now.Second + DateTime.Now.Minute + ".txt", exc.Message);
            }
        }



        //Files[0].InputStream.Read(binaryWriteArray, 0,
        //(int)Files[0].InputStream.Length);
        ////Open the file stream
        //FileStream objfilestream = new FileStream("c:\\" +
        //fileName, FileMode.Create, FileAccess.ReadWrite);
        ////Write the file and close it
        //objfilestream.Write(binaryWriteArray, 0,
        //binaryWriteArray.Length);
        //objfilestream.Close();
    }

    public class User
    {
        public int UserId;
        public string UserName;
    }

}